package com.neusoft.elmboot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.neusoft.elmboot.mapper.UserMapper;
import com.neusoft.elmboot.po.User;
import com.neusoft.elmboot.service.UserService;
import com.neusoft.elmboot.util.CommonUtil;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public User getUserByIdByPass(User user) {
		user.setPassword(CommonUtil.getSHA256Hash(user.getPassword()));
		User rUser=null;
		if (userMapper.getUserByIdByPass(user) != null) {
			rUser=userMapper.getUserByIdByPass(user);
			rUser.setPassword("");
		}
		return rUser;
	}

	@Override
	public int getUserById(String userId) {
		return userMapper.getUserById(userId);
	}

	@Override
	public int saveUser(User user) {
		user.setPassword(CommonUtil.getSHA256Hash(user.getPassword()));
		return userMapper.saveUser(user);
	}

	@Override
	public Double getBalanceByUserId(String userId){
		return userMapper.getBalanceByUserId(userId);
	}

	@Override
	public int updateBalance(User user){
		return userMapper.updateBalance(user);
	}
}